package util;

import java.sql.*;

public class BaseDB {
//    static final String DRIVER="com.mysql.jdbc.Driver";
//    static final String URL="jdbc:mysql://localhost:3305/test";
//    static final String DBNAME="root";
//    static final String DBPASS="root";

    static final String DRIVER="com.mysql.jdbc.Driver";
    static final String URL="jdbc:mysql://localhost:3305/test";
    static final String DBNAME="root";
    static final String DBPASS="root";
    /**
     * 连接数据库
     * @return
     */
    public static Connection getConn(){
        Connection conn=null;
        try{
            Class.forName(DRIVER);
            conn= DriverManager.getConnection(URL,DBNAME,DBPASS);
        }catch(ClassNotFoundException e){
            e.printStackTrace();
        }catch(SQLException e){
            e.printStackTrace();
        }
        return conn;
    }

    /**关闭数据库
     * @param conn
     * @param st
     * @param rs
     */
    public static void closeAll(Connection conn, Statement st, ResultSet rs){
        try{
            if(rs!=null){
                rs.close();
            }
            if(conn!=null){
                rs.close();
            }
            if(conn!=null){
                conn.close();
            }
        }catch(SQLException e){
            e.printStackTrace();
        }
    }

}
